package cn.wuxq.saa02ollama.controller;

import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/ollama")
public class OllamaController {

    @Autowired //对话模型，调用阿里云百炼平台
    private ChatModel chatModel;


    @GetMapping("/chat")
    public String doChat(@RequestParam(name = "msg", defaultValue = "你是谁") String message) {
        String call = chatModel.call(message);
        return call;
    }

    @GetMapping("/streamchat")
    public Flux<String> stream(@RequestParam(name = "msg", defaultValue = "你是谁") String message) {
        Flux<String> stream = chatModel.stream(message);
        return stream;
    }

}
